# 从typing模块导入常用类型注解工具
from typing import List, Dict, Tuple, Optional, Union, Any, Callable
import inspect


x = 100

# 定义一个类型，类似TypeScript 的type用来定义类型
# Callable[[参数类型列表], 返回值类型] 就是用来描述 “函数 / 可调用对象应该接收什么类型的参数、返回什么类型的值” 的注解方式
typeFun = Callable[[int, int], float]


def add(x: int, y: int) -> float:
    return x + y


def calculate(fun: typeFun, x: int, y: int):
    return fun(x, y)


res = calculate(add, 100, 200)
print("res====", res, "type(add)=", type(add) == "<class 'function'>")


def fun():
    frame_stack = inspect.currentframe()
    print("这是函数，可以调用", frame_stack)


def operate(x, y, z, *args, name="", **kwargs):
    print("x=", x, "y=", y, "z=", z, "name=", name, "args=", args, "kwargs=", kwargs)


if callable(fun):
    fun()

if callable(x):
    x()
else:
    print("x不是函数", type(x))

operate(1, 2, 3, (1, 2, 3), [4, 5, 6], name="linda", score=100, age=10, sub="chinese")
# 获得函数签名
signature_operate = inspect.signature(operate)

print(signature_operate.parameters)
print(signature_operate.__delattr__)


# 类型别名

Vector = List[float]
Matrix = List[Vector]


def multiply_matrix(a: Matrix, b: Matrix) -> Matrix:
    pass
